﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Xsl;
using System.Xml;

namespace RaveEngine.Engine
{
    public class XsltHelper
    {
        public static string ApplyXsltTransform(Stream input, Stream xslt)
        {
            XslCompiledTransform transform = new XslCompiledTransform();
            XmlTextReader xRead = new XmlTextReader(input);
            XmlTextReader xXslt = new XmlTextReader(xslt);
            StringWriter outputWriter = new StringWriter();
            XmlTextWriter xWrite = new XmlTextWriter(outputWriter);

            try
            {
                transform.Load(xXslt, XsltSettings.TrustedXslt, null);
                transform.Transform(xRead, xWrite);
            }
            catch (XmlException xmlException)
            {
                // CODE DEBT: Log exception
                throw xmlException;
            }
            catch (XsltException xsltException)
            {
                // CODE DEBT: Log exception
                throw xsltException;
            }
            catch (Exception ex)
            {
                // CODE DEBT: Log exception
                throw ex;
            }

            return outputWriter.ToString();
        }
    }
}